﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using BlueCrestStudio.DataVirtualization.Service.Data;

namespace BlueCrestStudio.DataVirtualization.Service
{
    [AspNetCompatibilityRequirements(
       RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerSession)]
    public class StockDataService : IStockDataService
    {
        private static List<Stock> _data = new List<Stock>();

        static StockDataService()
        {
            var random = new Random(100);
            for (int i = 0; i < 10000; i++)
            {
                var stock = new Stock
                {
                    Id = i,
                    Ask = 100 + random.Next(1, 100),
                    Bid = 50 + random.Next(1, 100),
                    Country = "TEST" + random.Next(1, 100),
                    Date = DateTime.Today.AddDays(random.Next(1, 100)),
                    High = 5 + random.Next(1, 100),
                    High2 = 10 + random.Next(1, 100),
                    High3 = 15 + random.Next(1, 100),
                    Low = 1 + random.Next(1, 100),
                    Low2 = 2 + random.Next(1, 100),
                    Low3 = 3 + random.Next(1, 100),
                    Mid = 5 + random.Next(1, 100),
                    Symbol = "BARC" + random.Next(1, 100),
                    Volume = random.Next(1000, 10000),
                    Baggage = Enumerable.Range(1, 1000).ToList()
                };

                _data.Add(stock);
            }
        }

        public StockDataService()
        {
            

            
        }
        public int FetchCount()
        {
            return _data.Count;
        }

        public List<Stock> FetchRange(int startIndex, int count)
        {
            var scope = _data.Skip(startIndex).Take(count).ToList();
            return scope;
        }
    }
}
